package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.constant.TimeConstants;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.SimpleDateFormat;

import flc.ast.R;
import flc.ast.bean.CommemorateBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class CommemorateAdapter extends StkProviderMultiAdapter<CommemorateBean> {


    public CommemorateAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new CommemorateProvider());
    }

    private class CommemorateProvider extends BaseItemProvider<CommemorateBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_commemorate;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, CommemorateBean bean) {
            baseViewHolder.setText(R.id.tvCommemorateItemTitle, bean.getTitle());
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            long timeSpan = TimeUtils.getTimeSpan(bean.getDate(), TimeUtils.getNowString(format), format, TimeConstants.DAY);
            if (timeSpan < 0) {//小于0表示今年这天已经过了
                timeSpan = Math.abs(timeSpan);
                baseViewHolder.setText(R.id.tvCommemorateItemTip, R.string.past_text);
            } else {
                baseViewHolder.setText(R.id.tvCommemorateItemTip, R.string.remain_text);
            }
            baseViewHolder.setText(R.id.tvCommemorateItemDay, timeSpan + "");
            if (bean.getPath().isEmpty()) {
                baseViewHolder.setBackgroundColor(R.id.rlCommemorateItem, bean.getColor());
                baseViewHolder.getView(R.id.rlCommemorateItemBg).setVisibility(View.GONE);
            } else {
                baseViewHolder.setBackgroundColor(R.id.rlCommemorateItem, 0);
                baseViewHolder.getView(R.id.rlCommemorateItemBg).setVisibility(View.VISIBLE);
                Glide.with(baseViewHolder.itemView).load(bean.getPath()).into((ImageView) baseViewHolder.getView(R.id.ivCommemorateItemImg));
            }
        }
    }

}
